<?php
namespace app\admin\controller;
use app\admin\org\Account;
use app\admin\org\Power;
use think\Controller;
use think\Response;

class Base extends Controller
{
    protected $account,$real_name,$power_id,$power_bicycle_place_id;
    public function __construct()
    {
        parent::__construct();
        $this->checklogin();
        if(!request()->isAjax()){
            $menu_list = Account::get_menu();
            $this->assign('menu_list',$menu_list);
        }
        $this->assign('controller_name',strtolower(request()->controller()));
        $this->assign('action_name',strtolower(request()->action()));
    }

    private function checklogin(){
        $controller_name = request()->controller();
        $controller_name = strtolower($controller_name);

        $is_login = false;
        $Power = new Power();
        if($Power->checkHasLogin($out)){
            $is_login = true;
            $this->account = $out['account'];
        }
        if($controller_name == 'login'){
            if($is_login){
                $this->redirect('admin/Index/index');exit;
            }
        }else{
            if(!$is_login){
                $this->redirect('admin/Login/login');exit;
            }
        }
    }

    private function checkpower(){
        $controller_name = request()->controller();
        $action_name = request()->action();
        $controller_name = strtolower($controller_name);

        if(!in_array($controller_name,array('pic','login'))){
            $action_name = strtolower($action_name);
            if(!Account::check_action($this->power_id,$controller_name,$action_name)){
                if(request()->isAjax()){
                    Response::create(rm(1,'您没有权限操作此功能',''),'json')->send();exit;
                }else{
                    $this->error('您没有权限操作此功能');exit;
                }
            }
        }
        return true;
    }

}